package com.zy.voteya.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zy.voteya.entity.Items;
import com.zy.voteya.entity.Vote;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author LiaoYan
 * @since 2025-09-20
 */
public interface VoteMapper extends BaseMapper<Vote> {

    @Select("select * from vote where id=#{id}")
    @Results({
            @Result(column = "id", property = "id", id = true),
            @Result(column = "id", property = "items",
            many = @Many(select = "selectItemsById", fetchType = FetchType.EAGER)),
    })
    Vote findById(int id);

    @Select("select * from items where vid = #{vid}")
    List<Items> selectItemsById(int id);

}
